﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using VelocityShop.Data;

namespace VelocityShop
{
    public static class DemoSettings
    {
        private static ICatalogProvider _instance;

        public static ICatalogProvider GetProvider()
        {
            if (_instance == null)
            {
                //_instance = GetSQLServerProvider();
                //_instance = GetAspNetCacheProvider();
                _instance = GetVelocityProvider();

            }

            return _instance;
            
        }

        private static ICatalogProvider GetVelocityProvider()
        {
            // Velocity-enabled provider
            Assembly providerAssembly = System.Reflection.Assembly.Load("VelocityShop.Data.Velocity");
            string providerTypeName = "VelocityShop.Data.Velocity.VelocityCatalogProvider";
            object providerInstance = providerAssembly.CreateInstance(providerTypeName,true);
            return (ICatalogProvider)providerInstance;
        }

        private static ICatalogProvider GetAspNetCacheProvider()
        {
            // ASP.Net Cache-enabled provider
            Assembly providerAssembly = System.Reflection.Assembly.Load("VelocityShop.Data.AspNetCache");
            string providerTypeName = "VelocityShop.Data.AspNetCache.AspNetCacheCatalogProvider";
            object providerInstance = providerAssembly.CreateInstance(providerTypeName, true);
            return (ICatalogProvider)providerInstance;
        }

        private static ICatalogProvider GetSQLServerProvider()
        {
            // SQLServer provider
            Assembly providerAssembly = System.Reflection.Assembly.Load("VelocityShop.Data.SQLServer");
            string providerTypeName = "VelocityShop.Data.SQLServer.SQLServerCatalogProvider";
            object providerInstance = providerAssembly.CreateInstance(providerTypeName, true);
            return (ICatalogProvider)providerInstance;
        }

    }
}
